#ifndef __ServerCommand__
#define __ServerCommand__

#pragma pack(push)
#pragma pack(1)

#include <iostream>
#include "GlobalConfig.h"
using namespace std;

const char command_encrypt_key [] = "a69c526cbe917e372e801100a590076c";

enum _cmd_type
{
    Cmd_Invalid  = 0,
    Cmd_Register,           // register client
    Cmd_Heartbeat,          // heart beat
    Cmd_Login,              // Login
    Cmd_ChangePassword,     // change password
    Cmd_UnBind,             // UnBind
    Cmd_Test                // Test Command
};

// command struct
typedef struct _cmd
{
    int         cmd_type;       // command type
    int         cmd_size;   // total command size
    char        data[DATALEN]; // actual data, add your data from here
}ServerCommand, *PServerCommand;

#define  SC_LEN  sizeof(ServerCommand)
//////////////////////////////////////////////////////////////////////////
// registration command structure
//////////////////////////////////////////////////////////////////////////

// register/heartbeat/login request
typedef struct _cmd_req
{
    char    hardware_id[KEY_LEN + 1];
    char    product_key[KEY_LEN + 1];
    char    username[USR_LEN + 1];
    char    password[PWD_LEN + 1];
    char    email[EML_LEN + 1];
}GeneralRequest, *PGeneralRequest;

// changepassword request
typedef struct _cmd_change_password
{
    GeneralRequest gr;
    char    new_pass[PWD_LEN+1];
}ChangePasswordRequest,*PChangePasswordRequest;

// response
typedef struct _cmd_res
{
    int cmd_state;
    int cmd_type;
    int data_len;
    char data[DATALEN];
}ServerResponse, *PServerResponse;

#define SR_LEN sizeof(ServerResponse)

typedef struct _product_key_info
{
    char        product_key[KEY_LEN + 1];
    char        username[USR_LEN +1];
    char        email[EML_LEN + 1];
    time_t      register_time;
    time_t      generate_time;
    time_t      duration;
    char        hardware_id[KEY_LEN + 1];
    int         state;
    int         client_type;
}ProductKeyInfo,*PProductKeyInfo;

struct request_data
{
    string user;
    string pass;
    string mail;
    string hwid;
    string pkey;
};

#pragma pack(pop)

#endif //__ServerCommand__